package com.aracky.system.service.impl;

import com.aracky.common.util.ConvertUtil;
import com.aracky.system.model.entity.SysTableHeader;
import com.aracky.system.mapper.SysTableHeaderMapper;
import com.aracky.system.model.form.SysTableHeaderForm;
import com.aracky.system.model.vo.SysTableHeaderVO;
import com.aracky.system.service.SysTableHeaderService;
import com.aracky.system.service.SysTableLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 查询表头信息表 服务实现类
 * </p>
 *
 * @author zengzhiping
 * @since 2022-07-18 10:05:43
 */
@Service
public class SysTableHeaderServiceImpl extends ServiceImpl<SysTableHeaderMapper, SysTableHeader> implements SysTableHeaderService {


    @Autowired
    private SysTableLineService sysTableLineService;

    @Autowired
    private SysTableHeaderService sysTableHeaderService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveOrUpdateTableHeader(SysTableHeaderForm sysTableHeaderForm) {
        SysTableHeader sysTableHeader = ConvertUtil.sourceToTarget(sysTableHeaderForm, SysTableHeader.class);
        this.saveOrUpdate(sysTableHeader);

        //保存列表字段
        sysTableLineService.saveOrUpdateTableLine(sysTableHeader.getHeadId(),sysTableHeaderForm.getSysTableLineList());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void removeBatch(Long[] headIds) {
        List<Long> list=new ArrayList<>();
        for(Long headId : headIds){
            list.add(headId);
        }
        sysTableHeaderService.removeBatchByIds(list);
    }

}
